﻿<%dim respagecode%><% 'UTF-8%>

<% ''投诉单管理%>
<% ''加载通用函数和数据库连接%>
<!--#include file="../Include/Start.asp"-->
<!--#include file="../Include/check_Permissions_do.asp"-->

<%
	'定义json对象
	Dim jsonObj,jsonObj_user
	Set jsonObj = jsObject()
	Set jsonObj_user = jsObject()
	UserID=ReplaceBadChar(Trim(Session("UserID")))
	
	dim act 
  	act=request("act")
  	
 	Dim rsObj,strSql
 	set rsObj=Server.CreateObject("ADODB.Recordset")
	Dim page ''当前查询页
	Dim RowCount''影响的记录条数
	''查询信息
	''id, 申诉者姓名, 申诉者性别, 申诉者联系电话, 申诉者通信地址, 申诉者电子邮箱, 
 	'' 被申诉方ID, 申诉类别, 申诉名称, 品牌, 型号, 价格, 凭证, 消费日期, 争议金额, 简述, 
  	''问题分类, 数量, 状态, 申诉要求, 受理人, 受理时间, 处理结果
	dim cid ,sszxm,sszxb,sszlxdh,ssztxfs,sszdzyx,bssfid,sslb,ssmc
	dim pp,xh,jg,pz,xfrq,zyje,js,wtfl,sl,zt,ssyq,slr,slsj,cljg
	dim spfl,spflA,spflB, spfl_txt,spflA_txt,spflB_txt
 
	''查询信息列表
	if "search"=act then
		page=ReplaceBadChar(Trim(request.Form("page")))&""
		cid=ReplaceBadChar(Trim(request.Form("cid")))''id 序列号
		ssmc=ReplaceBadChar(Trim(request.Form("ssmc")))''申诉名称
		sszxm=ReplaceBadChar(Trim(request.Form("sszxm")))''申诉者姓名
		pp=ReplaceBadChar(Trim(request.Form("pp")))''品牌
 
				
		jsonObj("rslist") = ""
		''添加用户信息
		jsonObj_user("UserID") = UserID 
		jsonObj_user("UserName") =ReplaceBadChar(Trim(Session("UserName")))
		Set jsonObj("customer") = jsonObj_user
	
	 
		''处理key值和value的对应关系 eg:"cardtype":[{"key":"0","value":"\u5931\u6548"},{"key":"1","value":"\u751F\u6548"}]
		Dim jsonObj_map 
		Set jsonObj_map = jsArray()
		
		set jsonObj_map(0) = jsObject()
		jsonObj_map(0)("key") = "0"
		jsonObj_map(0)("value") = "未提交"
		set jsonObj_map(1) = jsObject()
		jsonObj_map(1) ("key") = "1"
		jsonObj_map(1) ("value") = "待处理"
		set jsonObj_map(2) = jsObject()
		jsonObj_map(2) ("key") = "2"
		jsonObj_map(2) ("value") = "已处理"
		Set jsonObj("complaints_type") =  jsonObj_map''投诉单状态
		
		Set jsonObj_map = jsArray()
		set jsonObj_map(1) = jsObject()
		jsonObj_map(1)("key") = "1"
		jsonObj_map(1)("value") = "POS"
		set jsonObj_map(2) = jsObject()
		jsonObj_map(2) ("key") = "2"
		jsonObj_map(2) ("value") = "个人"
		Set jsonObj("map_flag") =  jsonObj_map''数据来源

		Set jsonObj_map = jsArray()
		set jsonObj_map(1) = jsObject()
		jsonObj_map(1)("key") = "1"
		jsonObj_map(1)("value") = "正常"
		set jsonObj_map(2) = jsObject()
		jsonObj_map(2) ("key") = "2"
		jsonObj_map(2) ("value") = "申请退货"
		set jsonObj_map(3) = jsObject()
		jsonObj_map(3) ("key") = "3"
		jsonObj_map(3) ("value") = "退货成功"
		Set jsonObj("map_state") =  jsonObj_map''数据来源

		''处理key值和value的对应关系--end	
		
		If ("" = UserID ) Then UserID = "-999hasd9huoad9e993jwoi982niuh9wncdisj99"
	 
		''添加查询结果信息
		''Dim rsObj,strSql
		strSql = " SELECT top 100 PERCENT uew.id as orderid1, uew.*  "  
		strSql =  strSql & " ,PE_User.TrueName ,efv.TrueName as build_user  "		
		strSql =  strSql & " FROM [T_登记单] uew  "		
		strSql =  strSql & " INNER JOIN PE_User ON uew.被申诉方ID = PE_User.UserID  "		
		strSql =  strSql & " INNER JOIN PE_User efv ON uew.受理人 = efv.userid  "		
		strSql =  strSql & " WHERE (uew.状态 = '1' Or uew.状态 = '2' Or uew.状态 = '3') "
		strSql =  strSql & " and uew.被申诉方ID = '"&Trim(Session("UserID"))&"'   "
		if (""<>cid) then strSql =  strSql & " and uew.id = '" & cid & "'  " end if
		if (""<>ssmc) then strSql =  strSql & " and uew.申诉名称    like '%" & ssmc & "%'  " end if  ''申诉名称
		if (""<>sszxm) then strSql =  strSql & " and uew.申诉者姓名  like '%" & sszxm & "%'  " end if  ''申诉者姓名
		if (""<>pp) then strSql =  strSql & " and uew.品牌  like '%" & pp & "%'  " end if ''品牌
		strSql =  strSql & " ORDER BY uew.orderid1 "
		
		ssmc=ReplaceBadChar(Trim(request.Form("ssmc")))''申诉名称
		sszxm=ReplaceBadChar(Trim(request.Form("sszxm")))''申诉者姓名
		pp=ReplaceBadChar(Trim(request.Form("spname")))''品牌

 		dim TotalRsNum ,PageSizeCur''TotalRsNum总记录数''PageSizeCur当前页记录数
		strSqlTemp = "select count(*)  from ( " & strSql & " ) kksds "
		TotalRsNum = PE_CLng(Conn.Execute(strSqlTemp)(0))
		''PageSize 页的记录数量
		PageSizeCur = PageSize ''当前页记录数
		if (PageSize*PE_CLng(page)>TotalRsNum or 0=TotalRsNum) then ''判断最后一页记录数是否和PageSize相等
			PageSizeCur= TotalRsNum Mod PageSize ''该页的时间记录数
		end if

		strSqlTemp = " SELECT ttkkk.* FROM (SELECT TOP " & CStr(PageSizeCur)
		strSqlTemp = strSqlTemp & "  mmsss.* FROM (SELECT TOP " & CStr(PageSize*PE_CLng(page)) & " nnfff.* FROM ( " 
		strSqlTemp = strSqlTemp &	strSql  
		strSqlTemp = strSqlTemp &  " ) nnfff) mmsss  ORDER BY mmsss.orderid1 DESC) ttkkk ORDER BY ttkkk.orderid1"
		''Response.Write strSqlTemp&"------<br>"
		Set jsonObj("rslist") = QueryToJSON(Conn, strSqlTemp)
		
		''添加分页信息
		'定义json对象
		Dim jsonObj_page
		Set jsonObj_page = jsObject()
			jsonObj_page("PageCur") = Page ''当前页	
			jsonObj_page("PageSizeCur") = PageSizeCur ''当前页记录数
			if (0=TotalRsNum  mod PageSize  ) then
				jsonObj_page("PageTotalNum")= TotalRsNum\PageSize''总页数
			else
				jsonObj_page("PageTotalNum")= TotalRsNum\PageSize+1''总页数
			end if
		Set jsonObj("page") = jsonObj_page 
		jsonObj("success") = 1 'false
	  	jsonObj("msg") = "记录查询成功！"
	''查询某条信息
	elseif "view"=act then 
		cid=ReplaceBadChar(Trim(request.Form("cid")))''id 序列号 
		
		jsonObj("rslist") = ""
		''添加用户信息
		jsonObj_user("UserID") = UserID 
		jsonObj_user("UserName") =ReplaceBadChar(Trim(Session("UserName")))
		Set jsonObj("customer") = jsonObj_user
	
	 
		''处理key值和value的对应关系 eg:"cardtype":[{"key":"0","value":"\u5931\u6548"},{"key":"1","value":"\u751F\u6548"}]
		'Dim jsonObj_map 
		Set jsonObj_map = jsArray()
		
		set jsonObj_map(0) = jsObject()
		jsonObj_map(0)("key") = "0"
		jsonObj_map(0)("value") = "未提交"
		set jsonObj_map(1) = jsObject()
		jsonObj_map(1) ("key") = "1"
		jsonObj_map(1) ("value") = "待处理"
		set jsonObj_map(2) = jsObject()
		jsonObj_map(2) ("key") = "2"
		jsonObj_map(2) ("value") = "已处理"
		set jsonObj_map(3) = jsObject()
		jsonObj_map(3) ("key") = "3"
		jsonObj_map(3) ("value") = "结束"
		Set jsonObj("complaints_type") =  jsonObj_map''投诉单状态
		
		Set jsonObj_map = jsArray()
		set jsonObj_map(1) = jsObject()
		jsonObj_map(1)("key") = "1"
		jsonObj_map(1)("value") = "POS"
		set jsonObj_map(2) = jsObject()
		jsonObj_map(2) ("key") = "2"
		jsonObj_map(2) ("value") = "个人"
		Set jsonObj("map_flag") =  jsonObj_map''数据来源


		''处理key值和value的对应关系--end	
		
		If ("" = UserID ) Then UserID = "-999hasd9huoad9e993jwoi982niuh9wncdisj99"
	 
		''添加查询结果信息
		''Dim rsObj,strSql
		strSql = " SELECT top 100 PERCENT uew.id as orderid1, uew.*  "  
		strSql =  strSql & " ,PE_User.TrueName ,efv.TrueName as build_user  "		
		strSql =  strSql & " FROM [T_登记单] uew  "		
		strSql =  strSql & " INNER JOIN PE_User ON uew.被申诉方ID = PE_User.Userid  "		
		strSql =  strSql & " INNER JOIN PE_User efv ON uew.受理人 = efv.userid and (1=2 "		
		if (""<>cid) then strSql =  strSql & " or uew.id = '" & cid & "'  " end if
		strSql =  strSql & " ) ORDER BY uew.orderid1 "
		''strSql =  strSql & " WHERE (HYKXH.state = '2' Or HYKXH.state = '3')  "
		''Response.Write strSql&"------<br>"   
		Set jsonObj("rslist") = QueryToJSON(Conn, strSql)
 
		strSql = "select isnull(uew.申诉要求 ,'') as ssyq  from [T_登记单] uew  WHERE 1=2 "
		if (""<>cid) then strSql =  strSql & " or uew.id = '" & cid & "'  " end if
		''Response.Write strSql&"------<br>"   
		ssyq = Conn.Execute(strSql)(0) 
		''rsObj.Open strSql, Conn, 1, 3
		''ssyq=""
		''If not (rsObj.BOF and  rsObj.EOF) Then 
		''	ssyq=rsObj("ssyq")
		''end if	
	
		
		''添加查询结果信息
		strSql = " SELECT * FROM T_数据字典  uew "  	
		strSql =  strSql & " WHERE 1=2 "
		if (""<>ssyq) then strSql =  strSql & " or uew.id in (" & ssyq & ")  " end if
		strSql =  strSql & "  ORDER BY uew.id "
		''Response.Write strSql&"------<br>"   
		Set jsonObj("checkboxArr") = QueryToJSON(Conn, strSql)

		jsonObj("success") = 1 'false
	  	jsonObj("msg") = "记录查询成功！"
	 	 
 	elseif "add"=act then ''增加
		jsonObj("msg") = "&#x64CD;&#x4F5C;&#x5931;&#x8D25;&#xFF0C;&#x8BF7;&#x91CD;&#x8BD5;..."'''' "操作失败，请重试..."
		jsonObj("success") = 0'"false"
		respagecode="complaints_merchant_add"
		if not(check_Permissions(UserID,respagecode)) then 
			jsonObj("msg") = "权限受限，操作失败!"
			jsonObj("success") = 0'"false"
			jsonObj("url") = "../passport/nopermission.asp"
		else''添加信息		
			cid=ReplaceBadChar(Trim(request.Form("cid"))) ''id
			sszxm=ReplaceBadChar(Trim(request.Form("sszxm"))) ''申诉者姓名
			sszxb=ReplaceBadChar(Trim(request.Form("sszxb"))) ''申诉者性别
			sszlxdh=ReplaceBadChar(Trim(request.Form("sszlxdh"))) ''申诉者联系电话
			ssztxdz=ReplaceBadChar(Trim(request.Form("ssztxdz"))) ''申诉者通信地址
			sszdzyx=ReplaceBadChar(Trim(request.Form("sszdzyx"))) ''申诉者电子邮箱
			
			bssfid=ReplaceBadChar(Trim(request.Form("bssfid"))) ''被申诉方ID
			sslb=ReplaceBadChar(Trim(request.Form("sslb"))) ''申诉类别
			ssmc=ReplaceBadChar(Trim(request.Form("ssmc"))) ''申诉名称
			
			pp=ReplaceBadChar(Trim(request.Form("pp"))) ''品牌
			xh=ReplaceBadChar(Trim(request.Form("xh"))) ''型号
			jg=ReplaceBadChar(Trim(request.Form("jg"))) ''价格
			pz=ReplaceBadChar(Trim(request.Form("pz"))) ''凭证			
			
			xfrq=ReplaceBadChar(Trim(request.Form("xfrq"))) ''消费日期
			zyje=ReplaceBadChar(Trim(request.Form("zyje"))) ''争议金额
			js=ReplaceBadChar(Trim(request.Form("js"))) ''简述
			wtfl=ReplaceBadChar(Trim(request.Form("wtfl"))) ''问题分类			
			
			sl=ReplaceBadChar(Trim(request.Form("sl"))) ''数量
			ssyq=ReplaceBadChar(Trim(request.Form("ssyq"))) ''申诉要求
			slr=ReplaceBadChar(Trim(request.Form("slr"))) ''受理人  
 
			''Dim rsObj,strSql
			set rsObj=Server.CreateObject("ADODB.Recordset")
			strSql = "Select  * from T_登记单 where id='"&cid&"' "
			''Response.Write strSql&"-----"
			rsObj.Open strSql, Conn, 1, 3
			If rsObj.BOF And rsObj.EOF Then 
				rsObj.AddNew '如果没记录新增，有记录update	
				strSql = "select ISNULL(MAX(id), 0)  from [T_登记单]  "
				cid = PE_CLng(Conn.Execute(strSql)(0)) + 1
			end if				
			''rsObj("id") = PE_CLng(id)
			rsObj("申诉者姓名")=sszxm
			rsObj("申诉者性别")=sszxb
			rsObj("申诉者联系电话")=sszlxdh
			rsObj("申诉者通信地址")=ssztxdz
			rsObj("申诉者电子邮箱")=sszdzyx
			
			rsObj("被申诉方ID")=bssfid
			rsObj("申诉类别")=sslb
			rsObj("申诉名称")=ssmc
			
			rsObj("品牌")=pp
			rsObj("型号")=xh
			rsObj("价格")=jg
			rsObj("凭证")=pz			
			
			rsObj("消费日期")=xfrq
			rsObj("争议金额")=zyje
			rsObj("简述")=js
			rsObj("问题分类")=wtfl
						
			rsObj("数量")=sl
			rsObj("申诉要求")=ssyq
			rsObj("受理人")=slr
			
			rsObj.Update
			rsObj.close
			''Set rsObj = Nothing
		 
			jsonObj("msg") = "添加成功，正在跳转..."
			jsonObj("success") = 1'"success"
			jsonObj("url") = "complaints_merchant.asp"
	 	 end if''权限判断end	 

elseif "edit"=act then'''修改
		jsonObj("msg") = "操作失败，请重试..."
		jsonObj("success") = 0'"false"
		respagecode="complaints_merchant_edit"
		if not(check_Permissions(UserID,respagecode)) then 
			jsonObj("msg") = "权限受限，操作失败!"
			jsonObj("success") = 0'"false"
			jsonObj("url") = "../passport/nopermission.asp"			
		else''修改信息

			cid=ReplaceBadChar(Trim(request.Form("cid"))) ''id
			sszxm=ReplaceBadChar(Trim(request.Form("sszxm"))) ''申诉者姓名
			sszxb=ReplaceBadChar(Trim(request.Form("sszxb"))) ''申诉者性别
			sszlxdh=ReplaceBadChar(Trim(request.Form("sszlxdh"))) ''申诉者联系电话
			ssztxdz=ReplaceBadChar(Trim(request.Form("ssztxdz"))) ''申诉者通信地址
			sszdzyx=ReplaceBadChar(Trim(request.Form("sszdzyx"))) ''申诉者电子邮箱
			
			bssfid=ReplaceBadChar(Trim(request.Form("bssfid"))) ''被申诉方ID
			sslb=ReplaceBadChar(Trim(request.Form("sslb"))) ''申诉类别
			ssmc=ReplaceBadChar(Trim(request.Form("ssmc"))) ''申诉名称
			
			pp=ReplaceBadChar(Trim(request.Form("pp"))) ''品牌
			xh=ReplaceBadChar(Trim(request.Form("xh"))) ''型号
			jg=ReplaceBadChar(Trim(request.Form("jg"))) ''价格
			pz=ReplaceBadChar(Trim(request.Form("pz"))) ''凭证			
			
			xfrq=ReplaceBadChar(Trim(request.Form("xfrq"))) ''消费日期
			zyje=ReplaceBadChar(Trim(request.Form("zyje"))) ''争议金额
			js=ReplaceBadChar(Trim(request.Form("js"))) ''简述
			wtfl=ReplaceBadChar(Trim(request.Form("wtfl"))) ''问题分类			
			
			sl=ReplaceBadChar(Trim(request.Form("sl"))) ''数量
			ssyq=ReplaceBadChar(Trim(request.Form("ssyq"))) ''申诉要求
			slr=ReplaceBadChar(Trim(request.Form("slr"))) ''受理人  
 
			''Dim rsObj,strSql
			''set rsObj=Server.CreateObject("ADODB.Recordset")
			strSql = "Select  * from T_登记单 where id='"&cid&"' "
			''Response.Write strSql&"-----<br>"
			rsObj.Open strSql, Conn, 1, 3
			If rsObj.BOF And rsObj.EOF Then 
				jsonObj("msg") =  "操作失败，请重试..."
				jsonObj("success") = 0'"false"
					rsObj.close
			else				
				''rsObj("id") = PE_CLng(id)
				rsObj("申诉者姓名")=sszxm
				rsObj("申诉者性别")=sszxb
				rsObj("申诉者联系电话")=sszlxdh
				rsObj("申诉者通信地址")=ssztxdz
				rsObj("申诉者电子邮箱")=sszdzyx
				
				rsObj("被申诉方ID")=bssfid
				rsObj("申诉类别")=sslb
				rsObj("申诉名称")=ssmc
				
				rsObj("品牌")=pp
				rsObj("型号")=xh
				rsObj("价格")=jg
				rsObj("凭证")=pz			
				
				rsObj("消费日期")=xfrq
				rsObj("争议金额")=zyje
				rsObj("简述")=js
				rsObj("问题分类")=wtfl
							
				rsObj("数量")=sl
				rsObj("申诉要求")=ssyq
				rsObj("受理人")=slr
				
				rsObj.Update
				rsObj.close
				''Set rsObj = Nothing
		 
				jsonObj("msg") = "添加成功，正在跳转..."
				jsonObj("success") = 1'"success"
				jsonObj("url") = "complaints_merchant.asp"			 	
			 	  
	 		end if	
		end if''权限判断end
			 	 
 elseif "delete"=act then''删除
 		respagecode="complaints_merchant_del"
		if not(check_Permissions(UserID,respagecode)) then 
			jsonObj("msg") = "权限受限，操作失败!"
			jsonObj("success") = 0'"false"
			jsonObj("url") = "../passport/nopermission.asp"
		else''删除记录
		    ''Dim  RowCount 
			cid=ReplaceBadChar(Trim(request.Form("id"))) ''id
 
		    RowCount = 0
		    If (cid <> "" ) Then 
		    	Conn.Execute ("delete from [T_登记单] where id='"&cid&"'"), RowCount
		    End If
		    If RowCount = 0 Then
		        jsonObj("success") = 0 'false
		        jsonObj("msg") = "记录删除失败。" 
		    Else
		        jsonObj("msg") = "删除成功，正在跳转..." 
						jsonObj("success") = 1'"success"
						jsonObj("url") = "complaints_merchant.asp"
		    End If '删除记录
  		end if''权限判断end
 
		 

 elseif "apply"=act then''提交 处理投诉单
 		respagecode="complaints_merchant_apply"
		if not(check_Permissions(UserID,respagecode)) then 
			jsonObj("msg") = "权限受限，操作失败!"
			jsonObj("success") = 0'"false"
			jsonObj("url") = "../passport/nopermission.asp"
		else''提交 处理投诉单
		    Dim  state 
			cid=ReplaceBadChar(Trim(request.Form("cid"))) ''id
			state=ReplaceBadChar(Trim(request.Form("state"))) ''投诉单状态 
			cljg=ReplaceBadChar(Trim(request.Form("cljg"))) ''处理结果

		  	RowCount = 0
		  	if ("1"=state) then''待处理投诉单，商户处理后提交结果，状态变为结束
			    If (cid <> ""   ) Then 
					set rsObj=Server.CreateObject("ADODB.Recordset")
					strSql = "Select  * from [T_登记单]  WHERE (id = "&cid&") "	
					rsObj.Open strSql, Conn, 1, 3
					If rsObj.BOF And rsObj.EOF Then
				        jsonObj("success") = 0 'false
				        jsonObj("msg") = "申请提交失败。"
					Else
						rsObj("状态") = "3" 
					  	rsObj("处理结果") = cljg ''处理结果
						rsObj.Update
						rsObj.close
				        jsonObj("msg") = "提交成功，正在跳转..."
						jsonObj("success") = 1'"success"
						jsonObj("url") = "complaints_merchant.asp"
					End If
			   
			    End If'''
	    	Elseif ("2"= state) then ''取消并收回待处理投诉单(商户提交后就变为结束状态)
	    		''修改订单状态
		    	strSql = " UPDATE [T_登记单] SET [状态] = '1' WHERE (id = "&cid&") "	    	    	
		    	Conn.Execute (strSql), RowCount
			    If RowCount = 1 Then
			        jsonObj("msg") = "取消收回投诉单成功，正在跳转..."
					jsonObj("success") = 1'"success"
					jsonObj("url") = "complaints_merchant.asp"
			    Else
			        jsonObj("success") = 0 'false
			        jsonObj("msg") = "取消收回投诉单失败。"
			    End If 
	    	End If
	    

  		end if''权限判断end
 
		 
  	End If

 
 

	'输出json对象
	jsonObj.Flush
	''Response.Write strSql&"-----"
 
	call CloseConn

''{
''    rslist : [ { name: "mac", desc: "computer",     
''                   price: 1000, quantity: 100, alert:null },
''                 { name: "ipod", desc: "music player", 
''                   price:  200, quantity: 200, alert:"on sale now!" },
''                 { name: "cinema display", desc: "screen",       
''                   price:  800, quantity: 300, alert:"best deal!" } ],
''    customer : { first: "John", last: "Public", level: "gold" }
''}

%>